#include <commands.h>
#include <user.h>
#include <defs.h>
#include <curses.h>

void Stop(track *sts) {
  Putc( COM1, TRAIN_STOP );
}

void Go(track *sts) {
  Putc( COM1, TRAIN_GO );
}

void Tr(track *sts, int train_number, int train_speed) {
  Putc( COM1, train_speed );
  Putc( COM1, train_number );
  sts->tr_speed[train_number] = train_speed;
}

void Rv(track *sts, int train_number) {
  Putc(COM1, 0);
  Putc(COM1, train_number);
  Delay(5);
  Putc(COM1, TRAIN_REVERSE);
  Putc(COM1, train_number);
  Delay(5);
  Putc(COM1, sts->tr_speed[train_number]);
  Putc(COM1, train_number);
}

void Sw(track *sts, int switch_number, char switch_direction) {
  if (switch_direction == 'S')
    Putc(COM1, TRAIN_SW_STRAIGHT);
  else
    Putc(COM1, TRAIN_SW_CURVED);
  Putc(COM1, switch_number);
  sts->sw_dir[switch_number] = switch_direction;
}
